1 module game_selector; 2 import commons; 3 4 bool isGameFolderValid(string gameFolder) 5 { 6 return std.file.exists(buildNormalizedPath(gameFolder, "assets")) && 7 std.file.exists(buildNormalizedPath(gameFolder, "source")) && 8 std.file.exists(buildNormalizedPath(gameFolder, "dub.template.json")); 9 } 10 11 12 private __gshared bool hasTypedGamepath = false; 13 private ChoiceResult typeGamePath(Choice* self, ref Terminal t, ref RealTimeConsoleInput input, in CompilationOptions _) 14 { 15 string gamePath; 16 while(!gamePath.length) 17 { 18 gamePath = getValidPath(t, "Type your game path: "); 19 if(!isGameFolderValid(gamePath)) 20 { 21 t.writelnError("The selected path '" ~ gamePath ~ "' is not valid. Please select a valid game folder."); 22 gamePath = null; 23 } 24 } 25 26 t.writelnSuccess("Selected game path '", gamePath, "'"); 27 changeGamePath(t, gamePath); 28 hasTypedGamepath = true; 29 30 return ChoiceResult.Continue; 31 } 32 33 void changeGamePath(ref Terminal t, string newGamePath) 34 { 35 configs["gamePath"] = newGamePath; 36 engineConfig["defaultProject"] = newGamePath; 37 t.writelnHighlighted("Opening project at ", newGamePath); 38 openSourceCodeEditor(newGamePath); 39 clearCache(); 40 } 41 42 ChoiceResult selectGameFolder(Choice* c, ref Terminal t, ref RealTimeConsoleInput input, in CompilationOptions cOpts) 43 { 44 import std.array; 45 import std.algorithm; 46 Choice[] extraChoices = 47 [ 48 Choice("Type the game path manually", &typeGamePath), 49 getBackChoice() 50 ]; 51 Choice[] choices = getProjectsAvailable().map!((string name) => Choice(name, null)).array; 52 if(isGameFolderValid(std.file.getcwd())) 53 choices = Choice(std.file.getcwd(), null) ~ choices; 54 Choice* selectedChoice = selectInFolderExtra( 55 "Select your game", 56 getHipPath("projects"), t, input, choices, extraChoices 57 ); 58 if(selectedChoice.onSelected != null) 59 selectedChoice.onSelected(selectedChoice, t, input, cOpts); 60 // Chose a path 61 if(selectedChoice.onSelected == null) 62 changeGamePath(t, selectedChoice.name); 63 if(hasTypedGamepath || selectedChoice.onSelected == null) 64 { 65 configs["selectedChoice"] = 0; 66 updateEngineFile(); 67 updateConfigFile(); 68 } 69 70 return ChoiceResult.Back; 71 }